﻿@*@model CantinhodaCegonha.Models.BingApi.SearchResponse*@

@{
    ViewBag.Title = "Pesquisa " + Request.QueryString["query"];
}

<h1>Resultados da pesquisa: <b>@Request.QueryString["query"]</b></h1>

@*<h3>
    Foram encontrados @Model.Web.Total resultados, relacionados com a pesquisa @Model.Query.SearchTerms
</h3>
<br />
<ul>
@foreach (var item in Model.Web.Results)
{
<li>
    <a href="@item.Url">@item.Title</a>
    <p>@item.Description</p>
    <p>@item.DisplayUrl</p>
    <br />
</li>
}
</ul>*@

<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    function parseQueryFromUrl() {
        var queryParamName = "query";
        var search = window.location.search.substr(1);
        var parts = search.split('&');
        for (var i = 0; i < parts.length; i++) {
            var keyvaluepair = parts[i].split('=');
            if (decodeURIComponent(keyvaluepair[0]) == queryParamName) {
                return decodeURIComponent(keyvaluepair[1].replace(/\+/g, ' '));
            }
        }
        return '';
    }
    google.load('search', '1', { language: 'pt-BR', style: google.loader.themes.GREENSKY });
    google.setOnLoadCallback(function () {
        var customSearchControl = new google.search.CustomSearchControl('017426591538039978673:u8irm-pzzpk');
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        var options = new google.search.DrawOptions();
        options.enableSearchResultsOnly();
        customSearchControl.draw('cse', options);
        var queryFromUrl = parseQueryFromUrl();
        if (queryFromUrl) {
            customSearchControl.execute(queryFromUrl);
        }
    }, true);
</script>
 
